<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">

    <title>生态瞬时评估 - 主页</title>

    <meta name="keywords" content="">
    <meta name="description" content="">

    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->

    <link rel="shortcut icon" href="../favicon.ico">
    <link href="../css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="../css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="../css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="../css/animate.css" rel="stylesheet">
    <link href="../css/style.css?v=4.1.0" rel="stylesheet">
</head>
<body>
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <h3 class="col-sm-offset-3 col-sm-6 text-center">添加元数据</h3>
    </div>
    <div class="row">
        <div class="col-sm-offset-3 col-sm-6">
            <form class="form-horizontal" style="margin-top: 20px">
                <div class="form-group">
                    <label for="metaname" class="col-sm-3 control-label">数据名称：</label>
                    <div class="col-sm-8">
                        <input type="text" placeholder="数据名称" class="form-control" id="metaname">
                    </div>
                </div>
                <div class="form-group">
                    <label for="metatype" class="col-sm-3 control-label">数据类型：</label>
                    <div class="col-sm-8">
                        <select name="" id="metatype" class="form-control">
                            <option value="0">布尔类型</option>
                            <option value="1">文本类型</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label for="Required" class="col-sm-3 control-label">是否必填：</label>
                    <div class="col-sm-8">
                        <select name="" id="Required" class="form-control">
                            <option value="0">否</option>
                            <option value="1">是</option>
                        </select>
                    </div>
                </div>

                <div class="col-sm-offset-3 col-sm-8">
                    <input type="button" id="addBtn" value="添加" class="btn btn-primary btn-block">
                </div>
            </form>
        </div>
    </div>

</div>




<script src="../js/jquery.min.js?v=2.1.4"></script>
<script src="../js/bootstrap.min.js?v=3.3.6"></script>

<script>
    $(document).ready(function () {
        $("#addBtn").click(function () {
            var metaName = $("#metaname").val();
            var metaType = $("#metatype option:selected").val()==0?"BOOL":"STRING";
            // console.log(metaType,metaName);
            var required = $("#Required option:selected").val();
            var token = sessionStorage.getItem("token");
            var testId = sessionStorage.getItem("testId");
            var _data = JSON.stringify({"experimentId":testId,"metaName":metaName,"metaType":metaType,"required":required});
            $.ajax({
                url:"http://123.206.18.189:8080/experiments/"+testId+"/experiment_metas",
                type:"POST",
                headers:{
                    authToken:token
                },
                contentType:"application/json",
                data:_data,
                complete:function (XMLHttpRequest) {
                    console.log(XMLHttpRequest.status);
                    if(XMLHttpRequest.status==200){
                        alert("数据添加成功！");
                        window.history.back();
                    }
                }

            })
        })
    })




</script>

</body>
</html>